
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> ##########################################################################################################
> #Replication Files for Housing Discrimination and the Toxics Exposure Gap in the United States: 
> #Evidence from the Rental Market  by Peter Christensen, Ignacio Sarmiento-Barbieri and Christopher Timmins
> ##########################################################################################################
> 
> #Clean the workspace
> rm(list=ls())
> cat("\014")
> local({r <- getOption("repos"); r["CRAN"] <- "http://cran.r-project.org"; options(repos=r)}) #set repo
> 
> 
> #Load Packages
> pkg<-c("dplyr","stargazer")
> lapply(pkg, require, character.only=T)
Loading required package: dplyr

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Loading required package: stargazer

Please cite as: 

 Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
 R package version 5.2.2. https://CRAN.R-project.org/package=stargazer 

[[1]]
[1] TRUE

[[2]]
[1] TRUE

> rm(pkg)
> 
> 
> #Descriptive
> dta_desc<-read.csv("../views/descriptive_RSEI.csv")
> 
> 
> colnames(dta_desc)<-c("Q1","Q2-Q3","Q4")
> #dta_desc<-round(dta_desc,2)
> dta_desc<-format(round(dta_desc, digits=3), nsmall = 3) 
> 
> for(j in 1:3) dta_desc[,j]<-trimws(dta_desc[,j])
> 
> dta_desc[2,] <-paste0("(",dta_desc[2,] ,")")
> dta_desc[4,] <-paste0("(",dta_desc[4,] ,")")
> dta_desc[6,] <-paste0("(",dta_desc[6,] ,")")
> dta_desc[8,] <-paste0("(",dta_desc[8,] ,")")
> dta_desc[10,]<-paste0("(",dta_desc[10,],")")
> dta_desc[12,]<-paste0("(",dta_desc[12,],")")
> dta_desc[14,]<-paste0("(",dta_desc[14,],")")
> dta_desc[16,]<-paste0("(",dta_desc[16,],")")
> dta_desc[18,]<-paste0("(",dta_desc[18,],")")
> dta_desc[20,]<-paste0("(",dta_desc[20,],")")
> dta_desc[22,]<-paste0("(",dta_desc[22,],")")
> dta_desc[24,]<-paste0("(",dta_desc[24,],")")
> dta_desc[26,]<-paste0("(",dta_desc[26,],")")
> dta_desc[28,]<-paste0("(",dta_desc[28,],")")
> dta_desc[30,]<-paste0("(",dta_desc[30,],")")
> dta_desc[32,]<-paste0("(",dta_desc[32,],")")
> dta_desc[34,]<-paste0("(",dta_desc[34,],")")
> dta_desc[36,]<-paste0("(",dta_desc[36,],")")
> dta_desc[38,]<-paste0("(",dta_desc[38,],")")
> 
> dta_desc$names<-NA
> dta_desc$names[1]<-"Toxic Concentration (K)"
> dta_desc$names[2]<-""
> dta_desc$names[3]<-"Cancer Score"
> dta_desc$names[4]<-""
> dta_desc$names[5]<-"Non Cancer Score"
> dta_desc$names[6]<-""
> dta_desc$names[7]<-"Rent (K)"
> dta_desc$names[8]<-""
> dta_desc$names[9]<-"Single Family Home"
> dta_desc$names[10]<-""
> dta_desc$names[11]<-"Apartment"
> dta_desc$names[12]<-""
> dta_desc$names[13]<-"Multi Family"
> dta_desc$names[14]<-""
> dta_desc$names[15]<-"Other Bldg. Type"
> dta_desc$names[16]<-""
> dta_desc$names[17]<-"Bedrooms"
> dta_desc$names[18]<-""
> dta_desc$names[19]<-"Bathrooms"
> dta_desc$names[20]<-""
> dta_desc$names[21]<-"Sqft."
> dta_desc$names[22]<-""
> dta_desc$names[23]<-"Assault"
> dta_desc$names[24]<-""
> dta_desc$names[25]<-"Groceries"
> dta_desc$names[26]<-""
> dta_desc$names[27]<-"Share of Hispanics"
> dta_desc$names[28]<-""
> dta_desc$names[29]<-"Share of African American"
> dta_desc$names[30]<-""
> dta_desc$names[31]<-"Share of Whites"
> dta_desc$names[32]<-""
> dta_desc$names[33]<-"Poverty Rate"
> dta_desc$names[34]<-""
> dta_desc$names[35]<-"Unemployment Rate"
> dta_desc$names[36]<-""
> dta_desc$names[37]<-"Share of College Educated"
> dta_desc$names[38]<-""
> 
> dta_desc<- dta_desc[,c("names","Q1","Q2-Q3","Q4")]
> 
> 
> # # -----------------------------------------------------------------------
> #Ttest
> # # -----------------------------------------------------------------------
> 
> dta<-read.csv("../views/descriptive_RSEI_ttest.csv")
> 
> colnames(dta)<-c("0th-25th","25th-75th","75th-100th")
> dta<-round(dta, 4)
> 
> 
> dta<-format(round(dta, digits=3), nsmall = 3) 
> 
> for(j in 1:3) dta[,j]<-trimws(dta[,j])
> dta
   0th-25th 25th-75th 75th-100th
1    -6.826     2.787     15.909
2     1.342     0.495      0.569
3     1.232     1.212      2.712
4     0.615     0.227      0.260
5    -1.655     3.589      4.198
6     0.714     0.263      0.303
7     5.450    -0.313     -0.279
8     0.104     0.038      0.044
9     0.050    -0.049     -0.102
10    0.029     0.011      0.012
11   -0.013    -0.008      0.028
12    0.027     0.010      0.011
13    0.952     0.024      0.059
14    0.036     0.013      0.015
15    0.012     0.033      0.015
16    0.024     0.009      0.010
17    1.851    -0.133     -0.130
18    0.081     0.029      0.033
19    1.476    -0.098     -0.026
20    0.049     0.018      0.021
21  549.747   -16.946      5.284
22   59.191    21.817     25.083
23  284.077   -15.264      4.610
24   11.152     4.140      4.756
25  185.459    -0.849     -3.000
26    0.991     0.366      0.420
27    0.088     0.022     -0.031
28    0.013     0.005      0.005
29   -0.003     0.026      0.066
30    0.019     0.007      0.008
31    0.907    -0.039     -0.046
32    0.016     0.006      0.007
33    0.034     0.048      0.026
34    0.013     0.005      0.005
35    0.039     0.002      0.002
36    0.006     0.002      0.002
37    0.418    -0.011      0.013
38    0.010     0.004      0.004
> 
> 
> for(j in seq(1,37,by=2)){
+   for(k in 1:3){
+     
+     value<-dta[j,k] #format(round(, 2), nsmall = 2, big.mark=",")
+     tscore<-abs(as.numeric(dta[j,k])/as.numeric(dta[j+1,k]))
+     
+     dta[j,k] <-ifelse(tscore>=2.576, paste0(value,"***"),
+                       ifelse(tscore>=1.96 & tscore<2.576, paste0(value ,"**"),
+                              ifelse(tscore>=1.645 & tscore<1.96, paste0(value,"*"),paste0(value ))))
+     dta[j+1,k] <-paste0("(",dta[j+1,k],")") #for standard errors
+   }
+   
+ }
> 
> dta<-dta[,c(2,3)]
> 
> 
> # Bind rows ----------------------------------------------------------------
> dta_bind<-bind_cols(dta_desc,dta)
> stargazer(dta_bind,summary=FALSE,type="text", rownames = FALSE,out="../views/tableA2.tex")

================================================================================
names                        Q1       Q2-Q3      Q4      25th-75th   75th-100th 
--------------------------------------------------------------------------------
Toxic Concentration (K)    11.903    19.730    30.604    2.787* * *  15.909* * *
                          (11.987)  (23.091)  (46.262)    (0.495)      (0.569)  
Cancer Score                5.759     7.871    10.361    1.212* * *  2.712* * * 
                           (9.591)  (11.310)  (15.157)    (0.227)      (0.260)  
Non Cancer Score            3.231     5.791     6.273    3.589* * *  4.198* * * 
                          (10.368)  (13.041)  (12.170)    (0.263)      (0.303)  
Rent (K)                    2.235     1.703     1.840   -0.313* * *  -0.279* * *
                           (2.436)   (1.335)   (1.549)    (0.038)      (0.044)  
Single Family Home          0.213     0.171     0.114   -0.049* * *  -0.102* * *
                           (0.410)   (0.376)   (0.318)    (0.011)      (0.012)  
Apartment                   0.128     0.131     0.152      -0.008     0.028* *  
                           (0.335)   (0.338)   (0.359)    (0.010)      (0.011)  
Multi Family                0.490     0.523     0.577      0.024*    0.059* * * 
                           (0.500)   (0.500)   (0.494)    (0.013)      (0.015)  
Other Bldg. Type            0.168     0.175     0.157    0.033* * *     0.015   
                           (0.374)   (0.380)   (0.364)    (0.009)      (0.010)  
Bedrooms                    2.435     2.267     2.331   -0.133* * *  -0.130* * *
                           (1.129)   (0.981)   (0.934)    (0.029)      (0.033)  
Bathrooms                   1.540     1.425     1.485   -0.098* * *    -0.026   
                           (0.764)   (0.630)   (0.640)    (0.018)      (0.021)  
Sqft.                      716.327   749.188   694.330    -16.946       5.284   
                          (730.209) (759.089) (756.266)   (21.817)    (25.083)  
Assault                    220.546   183.757   253.292  -15.264* * *    4.610   
                          (319.979) (272.190) (387.808)   (4.140)      (4.756)  
Groceries                  31.926    25.144    28.438    -0.849* *   -3.000* * *
                          (44.011)  (22.791)  (35.535)    (0.366)      (0.420)  
Share of Hispanics          0.101     0.131     0.089    0.022* * *  -0.031* * *
                           (0.163)   (0.208)   (0.130)    (0.005)      (0.005)  
Share of African American   0.208     0.233     0.299    0.026* * *  0.066* * * 
                           (0.271)   (0.286)   (0.337)    (0.007)      (0.008)  
Share of Whites             0.687     0.643     0.612   -0.039* * *  -0.046* * *
                           (0.274)   (0.270)   (0.316)    (0.006)      (0.007)  
Poverty Rate                0.238     0.291     0.274    0.048* * *  0.026* * * 
                           (0.206)   (0.219)   (0.228)    (0.005)      (0.005)  
Unemployment Rate           0.084     0.087     0.093      0.002        0.002   
                           (0.079)   (0.083)   (0.099)    (0.002)      (0.002)  
Share of College Educated   0.286     0.264     0.281   -0.011* * *  0.013* * * 
                           (0.155)   (0.149)   (0.182)    (0.004)      (0.004)  
--------------------------------------------------------------------------------
> 
> system("rm ../views/descriptive_RSEI.csv")
> system("rm ../views/descriptive_RSEI_ttest.csv")
> 
> #end
> 
> 
> proc.time()
   user  system elapsed 
  1.381   0.111   1.503 
